package io.rasterizing;

import static util.MatrixOperationsF.ar;
import graphics.rasterizing.Rasterizer;
import graphics.rasterizing.camera.CameraPosition;
import graphics.rasterizing.model.Model;
import graphics.rasterizing.projection.PerspectiveProjection;
import graphics.rasterizing.projection.SimpleProjection;
import graphics.rasterizing.shading.RandomColorShader;

import java.io.FileNotFoundException;

import javax.swing.JFrame;

import org.junit.Test;

import drawing.CgPanel;

public class SimpleReaderTest {
	private int xmax = 300;
	private int ymax = 300;

	@Test
	public void test() {
		ModelReader reader;
		try {
			reader = new SimpleReaderToIndexTriangleMesh("c:\\cgobjects\\teapot.obj");
		} catch (FileNotFoundException e) {
			System.err.println("fail");
			return;
		}
		JFrame frame = new JFrame();
		CgPanel panel = new CgPanel();
		frame.getContentPane().add(panel);
		frame.setBounds(0, 0, 502, 502);
		panel.setBounds(0, 0, 501, 501);
		frame.setVisible(true);

		Model model = reader.read();
		System.out.println("done reading");
		Rasterizer rast = new Rasterizer(xmax, ymax);
		rast.setShader(new RandomColorShader());
		rast.setCameraPosition(new CameraPosition(ar(10, 10,10, 1), ar(-1, -1, -1,
				1), ar(1, 0, -1, 1)));

		rast.loadModel(model);
		rast.setProjection(new PerspectiveProjection(ar(0,0,0,1), ar(4,4,-8,1)));
		int[][] value = rast.rasterize();
		while (true) {
			panel.setVisible(true);
			System.out.println("rasterized");
			for (int i = 0; i < value.length; i++) {
				for (int j = 0; j < value[0].length; j++) {
					panel.drawPixel(i, j, value[i][j]);
				}
			}
			panel.repaint();
		}

	}


	
}
